import { Button, Divider, Dropdown, Menu, message } from 'antd'
import React, { useState, useRef, useEffect } from 'react'
import { PageHeaderWrapper } from '@ant-design/pro-layout'
import ProTable, { ProColumns, ActionType } from '@ant-design/pro-table'
import { connect, history, Link } from 'umi'
import { queryRule } from '../../service'

const TableList = (props) => {
  const actionRef = useRef()

  const columns = [
    {
      title: '工号',
      dataIndex: 'code',
      hideInSearch: true,
    },
    {
      title: '姓名',
      dataIndex: 'name',
      render: (item, record) => (
        <Link to={`/info/details/${record.oid}`}>{item}</Link>
      ),
    },
    {
      title: '公司',
      dataIndex: 'orgname',
    },
    {
      title: '部门',
      dataIndex: 'unitname',
    },
    {
      title: '岗位',
      dataIndex: 'jobname',
    },
    {
      title: '职级',
      dataIndex: 'jobLevel',
      hideInSearch: true,
    },
    {
      title: '操作',
      dataIndex: 'option',
      valueType: 'option',
      render: (item, record) => (
        <>
          <a onClick={() => itemEdit(record)}>修改</a>
          <Divider type="vertical"/>
          <a onClick={() => itemDetail(record)}>详情</a>
        </>
      ),
    },
  ]

  const itemEdit = (item) => {
    history.push(`/info/edit/${item.oid}`)
  }

  const itemDetail = (item) => {
    history.push(`/info/details/${item.oid}`)
  }

  const handleMainExport = () => {
    window.open('/hr-ssc/api/api-admin/export/exportNewEntry?isEntryStatus=1')
  }
  const handleEducationExport = () => {
    window.open('/hr-ssc/api/api-admin/export/exportEducation?isEntryStatus=1')
  }
  const handleSocietyExport = () => {
    window.open('/hr-ssc/api/api-admin/export/exportSociety?isEntryStatus=1')
  }
  const handleInorgExport = () => {
    window.open('/hr-ssc/api/api-admin/export/exportInorgname?isEntryStatus=1')
  }
  const handleFamilyExport = () => {
    window.open('/hr-ssc/api/api-admin/export/exportFamily?isEntryStatus=1')
  }

  return (
    <PageHeaderWrapper>
      <ProTable
        actionRef={actionRef}
        rowKey="oid"
        request={(params) => queryRule(params)}
        columns={columns}
        toolBarRender={(action, { selectedRows }) => [
          <Button type="primary" onClick={handleMainExport}>导出人员主信息</Button>,
          <Button type="primary" onClick={handleEducationExport}>导出教育信息</Button>,
          <Button type="primary" onClick={handleSocietyExport}>导出工作信息</Button>,
          <Button type="primary" onClick={handleInorgExport}>导出政治信息</Button>,
          <Button type="primary" onClick={handleFamilyExport}>导出家庭信息</Button>,
        ]}
      />
    </PageHeaderWrapper>
  )
}

export default connect(({ productAndCategory, loading }) => ({
  productAndCategory,
  loading: loading.models.productAndCategory,
}))(TableList)
